package com.gavin.sample.security;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.apache.commons.codec.binary.Base64;

public class MDClient {
	public String secret = "abcdefghijklmnopqrstuvwxyz";
	
	public String getDigest(Map<String, String> params) {
		Set<String> keySet = params.keySet();
		TreeSet<String> sortSet = new TreeSet<>();
		sortSet.addAll(keySet);
		String keyvalueStr = "";
		Iterator<String> it = sortSet.iterator();
		while (it.hasNext()) {
			String key = it.next();
			String value = params.get(key);
			keyvalueStr += key + value;
		}
		
		keyvalueStr += secret;
		return Base64.encodeBase64String(keyvalueStr.getBytes());
	}
}
